<template>
  <view class="content">
    <u-cell-group>
      <u-cell
        :value="item.deal_text"
        v-for="item in productList"
        :key="item.id"
      >
        <view slot="title" class="u-slot-title">
          <view v-for="son in item.OrderProduct" :key="son.id">
            {{ son.products.name }}
          </view>
        </view>
        <view slot="label" class="u-slot-label">
          <view style="color: #909193">
            下单时间：{{
              $u.timeFormat(item.createtime, "yyyy年mm月dd日 hh:MM")
            }}
          </view>
          <view class="btn">
            <u-button
              type="primary"
              :customStyle="btnStyle"
              size="mini"
              text="详情"
              @click="getToinfo(item.id)"
            ></u-button>
            <u-button
              type="error"
              :customStyle="btnStyle"
              size="mini"
              text="删除"
              @click="getDelData(item, 'del')"
            >
            </u-button>
          </view>
        </view>
      </u-cell>
    </u-cell-group>

    <u-modal
      :show="show"
      :content="content"
      :showCancelButton="true"
      @confirm="confirm"
      @cancel="show = false"
    ></u-modal>
    <u-toast ref="uToast"></u-toast>
  </view>
</template>

<script>
export default {
  data() {
    return {
      btnStyle: {
        width: "10%",
        display: "inline-block",
        marginRight: "5px",
        marginTop: "10px",
        lineHeight: "20px",
      },
      productList: [],
      LoginAdmin: {},
      show: false,
      content: "确认删除当前订单?",
      // 客户id
      id: 0,
      // del: 表示是调用删除确认框， apply：表示是调用申请确认框
      action: "del",
    };
  },
  methods: {
    async getData() {
      let result = await this.$u.api.manage.ProOrderIndex();
      console.log(result);

      if (result.code === 0) {
        this.$refs.uToast.show({
          type: "error",
          message: result.msg,
          duration: 1500,
        });
      }

      this.productList = result.data;
    },
    getToinfo(proId) {
      this.$u.route("/pages/manage/proOrder/info/info", { proId });
    },
    getDelData(item, action) {
      this.show = true;

      this.id = item.id;

      this.action = action;
    },
    async confirm() {
      this.show = false;

      if (this.action === "del") {
        let result = await this.$u.api.manage.SubOrderDel({
          subOrderId: this.id,
        });

        if (result.code === 1) {
          this.$refs.uToast.show({
            type: "success",
            message: result.msg,
            duration: 1500,
          });
          this.getData();
        }
      }
    },
  },
  onShow() {
    this.getData();

    this.LoginAdmin = uni.getStorageSync("LoginAdmin")
      ? uni.getStorageSync("LoginAdmin")
      : {};
  },
};
</script>